package com.bosc.modeling.service;

import com.bosc.modeling.dao.gen.UserEntityMapper;
import com.bosc.modeling.pojo.gen.UserEntity;
import com.bosc.modeling.pojo.gen.UserEntityExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserEntityMapper userEntityMapper;
    public List<UserEntity> getUserByName(String userName, String userPWD, short isAdmin){
        UserEntityExample example = new UserEntityExample();
        example.createCriteria().andUserEmailEqualTo(userName).andUserPasswordEqualTo(userPWD).andIsAdminEqualTo(isAdmin);
        return userEntityMapper.selectByExample(example);

    }
    public List<UserEntity> getUserList(){
        UserEntityExample example = new UserEntityExample();
        return userEntityMapper.selectByExample(example);

    }
    public int delUser(int id){
        return userEntityMapper.deleteByPrimaryKey(id);

    }
    public List<UserEntity> searchUser(String name){
        UserEntityExample example = new UserEntityExample();
        example.createCriteria().andUserNameLike("%"+name+"%");
        return userEntityMapper.selectByExample(example);

    }
    public List<UserEntity> getUserByEmail(String email){
        UserEntityExample example = new UserEntityExample();
        example.createCriteria().andUserEmailEqualTo(email);
        return userEntityMapper.selectByExample(example);

    }
    public int insertUser(UserEntity user){
        return userEntityMapper.insertSelective(user);

    }
    public int updateUser(UserEntity user){
        return userEntityMapper.updateByPrimaryKeySelective(user);

    }
    public UserEntity getUserById(int id){
        return userEntityMapper.selectByPrimaryKey(id);

    }
    public List<UserEntity> getUserById(String userId){
        UserEntityExample example = new UserEntityExample();
        example.createCriteria().andUserIdEqualTo(userId);
        return userEntityMapper.selectByExample(example);

    }
}
